/**
 * fileName:  RegionDictWriter.java
 * author:  lr
 * Company:  Cloudland Studio
 * Createdate:  2014-7-8 下午04:39:56
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-7-8          lr            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.store.write;

import javax.annotation.Resource;

import org.cloudland.commercial.masterdata.store.DatabaseWrite;
import org.cloudland.commercial.masterdata.store.entity.RegionEntity;
import org.cloudland.jdbc.ibatis.masterdata.entity.FruitCategoryEntity;
import org.cloudland.jdbc.ibatis.masterdata.entity.RegionDictEntity;
import org.cloudland.jdbc.ibatis.masterdata.handler.FruitCategoryMapper;
import org.cloudland.jdbc.ibatis.masterdata.handler.RegionDictMapper;
import org.cloudland.util.Randoms;
import org.springframework.stereotype.Service;

/**
 * <pre>
 * 地区字典领域层写操作
 * 使用 java.lang.Object#toString(), 或者 {@link java.lang.Character Character} 等标签
 * </pre>
 * 
 * @ClassName RegionDictWriter
 * @author lr
 * @version %I%, %G%
 * @see
 * @since JDK1.6
 * 
 */
@Service
public class RegionDictWriter implements DatabaseWrite<RegionEntity> {

	@Resource(name = "regionDictMapper")
	private RegionDictMapper regionDictMapper;

	/**
	 * <pre>
	 * TODO 请充分描述该构造函数的作用，及其参数的作用。
	 * </pre>
	 * 
	 */
	public RegionDictWriter() {
		// TODO Auto-generated constructor stub
	}

	public void save(RegionEntity entity) {

		String uuid = Randoms.uuid();
		Integer sort = Integer.parseInt(entity.getSort().toString());

		entity.setRegionId(uuid);

		RegionDictEntity daoEntity = new RegionDictEntity(entity.getRegionId(),
				entity.getRegionName(), sort, entity.getRegionParentId());
		regionDictMapper.add(daoEntity);

	}

	public void update(RegionEntity entity) {
		Integer sort = Integer.parseInt(entity.getSort().toString());

		RegionDictEntity daoEntity = new RegionDictEntity(entity.getRegionId(),
				entity.getRegionName(), sort, entity.getRegionParentId());
		regionDictMapper.update(daoEntity);
	}

	public void delete(RegionEntity entity) {
		RegionDictEntity daoEntity = new RegionDictEntity(entity.getRegionId(),
				entity.getRegionName(), 1, entity.getRegionParentId());
		regionDictMapper.delete(daoEntity);
	}

}
